<template>
	<view class="flex-col page">
		<view class="topView">
			<view class="flex-row-flex-start">
				<image class="avatarImage" :src="avatar" mode=""></image>
				<view class="">
					<view class="nickname">
						{{ nickname }}
					</view>
					<view class="nickname">
						{{ phone }}
					</view>
				</view>

			</view>

			<view class="topView1 flex-row-space-between">
				<view class="">
					<view class="money">
						{{ Number(money)}}
					</view>
					<view class="moneyTitle">
						总资产(元)
					</view>
				</view>
				<view class="chong flex-row-center" @click="toPath('/bundle/pages/wallet/wallet')">
					我的钱包
				</view>

			</view>

		</view>

		<view class="topView2 flex-row-space-between">
			<view @click="toPath('/bundle/pages/user_ollection/user_ollection')"
				class="topView3 flex-row-space-between">
				<view class="">
					<view class="topView3Title">
						我收藏过的
					</view>
					<view class="topView3Title1">
						已收藏{{collect_count}}人
					</view>
				</view>
				<image class="topView3Image" src="/static/my/11.png" mode=""></image>

			</view>
			<view @click="toPath('/bundle/pages/coupon/coupon')" class="topView3 flex-row-space-between">
				<view class="">
					<view class="topView3Title">
						我的优惠卷
					</view>
					<view class="topView3Title1">
						{{ coupon_count }}张优惠卷
					</view>
				</view>
				<image class="topView3Image" src="/static/my/12.png" mode=""></image>

			</view>
		</view>
		<view class="bottom" style="margin-top: 20rpx;">
			<view class="bottom-box">
				<view class="bottom-top">
					<text>其他功能</text>
				</view>
				<view class="bottom-b">
					<view class="bottom-b1" @click="toPath('/bundle/pages/feedback/feedback')">
						<image src="../../static/my/1.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>意见反馈</text>
					</view>
					<view class="bottom-b1" @click="toPath('/bundle/pages/user_address/user_address')">
						<image src="../../static/my/2.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>地址管理</text>
					</view>

					<view class="bottom-b1" @click="call">
						<image src="../../static/my/6.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>电话客服</text>
					</view>
					<!-- 	<view class="bottom-b1" @click="toPath('/pages/service/service')">
						<image src="../../static/my/8.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>在线客服</text>
					</view> -->
					<view class="bottom-b1" @click="toPath('/pages/zuju/myzuju')">
						<image src="/static/index/zju.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>我的组局</text>
					</view>
					<view class="bottom-b1" @click="toPath('/pages/zuju/putzuju')">
						<image src="/static/index/zj.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>发布组局</text>
					</view>
					<view class="bottom-b1" @click="toPath('/bundle/pages/settled/settled')">
						<image src="../../static/my/3.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>达人入驻</text>
					</view>
					<view class="bottom-b1" @click="toPath('/bundle/pages/user_profile/user_profile')">
						<image src="../../static/my/7.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>设置</text>
					</view>
					<view class="bottom-b1" @click="toPath('/bundle/pages/daili/daili')">
						<image src="/static/index/gerendaili.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>个人代理</text>
					</view>
					<view class="bottom-b1" @click="toPath1">
						<image src="/static/index/fenxiaoshangguanli.png" style="width: 60rpx; height: 60rpx;" mode="">
						</image>
						<text>渠道商申请</text>
					</view>
					<view class="bottom-b1" @click="toPath('/bundle/pages/daili/daili2')">
						<image src="/static/index/gerendaili.png" style="width: 60rpx; height: 60rpx;" mode=""></image>
						<text>城市代理申请</text>
					</view>
					
					<!-- {
							path: '/bundle/pages/daili/daili',
							name: '个人代理',
							icon: '/static/index/csdl.png'
						},
						{
							path: '/bundle/pages/settled/settled',
							name: '我要入驻',
							icon: '/static/index/wyrz.png'
						},
						{
							path: '/bundle/pages/daili/daili1',
							name: '合伙申请',
							icon: '/static/index/yqhy.png'
						}, -->
				</view>
			</view>

		</view>
		<view>
			<Tabbar :value='4' />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				"nickname": "",
				"mobile": "",
				"money": 0,
				"overdue_time": "",
				"avatar": "",
				"sex": 0,
				"balance": 0,
				"collect_count": 0,
				"coupon_count": 0,
				"news": 0,
				"unpaid": 0,
				"unpaid_order": null,
				"phone": "",
				end_t: '',
				mobiles: '',
				new1: '',
				show: false,
				reft: 'https://chat.yunqiaokefu.net/#/yqLink?teamID=95ff59ee-3870-4490-9eb5-f06b5966e283', //客服
				phone1: ''
			};
		},
		onShow() {
			this.init();
			/* this.newsss() */
		},
		onLoad() {
			/* 	if (location.href.indexOf('code') == -1&&!uni.getStorageSync('openid')) {
					this.getLogin()
				} */
			this.$http.post('api/sys/ad', {
				id: 18
			}).then(res => {
				/* console.log(res,'xxxx')
				let { mobile } = res; */
				this.phone1 = res.value;
				// this.technician_mobile = res.value;
			})
		},
		methods: {
			newsss() {
				this.$http.post('api/user/news').then(res => {
					// console.log(res);
					this.new1 = res
					if (this.new1) {
						this.show = true
					}
				})
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			},
			getLogin() {

				let baseurl = ''
				if (process.env.NODE_ENV === 'development') {
					baseurl = 'https://play.bozhoukeji.cn/h5'; // 这里做一下转译，要不然微信会忽略到#后面的参数
				} else {
					baseurl = location.origin; // 这里做一下转译，要不然微信会忽略到#后面的参数
				}
				let redirectURL = encodeURIComponent(
					(
						baseurl +
						window.location.pathname +
						window.location.hash
					).split("&code")[0]
				); //获取地址
				// console.log(redirectURL, '8998');

				const base = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=";
				let appid = 'wxf9eec50de3085fff'; //应用授权作用域
				let scope = "snsapi_userinfo";

				window.location.href =
					base +
					appid +
					"&redirect_uri=" +
					redirectURL +
					"&response_type=code&scope=" +
					scope +
					'&state=' + encodeURIComponent(location.origin) +
					"#wechat_redirect";
			},
			showtime(endtime) {
				var nowtime = new Date(), //获取当前时间
					endtime = new Date(endtime.replace(/-/g, '/')); //定义结束时间
				var lefttime = endtime.getTime() - nowtime.getTime(), //距离结束时间的毫秒数
					leftd = Math.floor(lefttime / (1000 * 60 * 60 * 24)), //计算天数
					lefth = Math.floor(lefttime / (1000 * 60 * 60) % 24), //计算小时数
					leftm = Math.floor(lefttime / (1000 * 60) % 60), //计算分钟数
					lefts = Math.floor(lefttime / 1000 % 60); //计算秒数
				if (lefttime <= 0) {
					return '已过期'
				}
				return this.add0(leftd) + "天" + this.add0(lefth) + ":" + this.add0(leftm) + ":" + this.add0(
					lefts); //返回倒计时的字符串
			},
			//导航栏图标事件
			onNavigationBarButtonTap: function(e) {
				let {
					index
				} = e;
				if (index === 1) {
					uni.navigateTo({
						url: "/bundle/pages/message/message"
					})
				}
				if (index === 0) {
					uni.navigateTo({
						url: "/bundle/pages/user_profile/user_profile"
					})
				}
				console.log(index);
			},
			add0(a) {
				a = Number(a)
				return a < 10 ? '0' + a : a;
			},
			init() {
				// 获取个人信息
				this.$http.post('api/user/detail').then(res => {
					uni.setStorageSync('user', res)
					// console.log(res);
					this.is_partner = res.is_partner
					this.is_personal = res.is_personal
					this.is_technician = res.is_technician
					for (let i in res) {
						// console.log(res, "会员信息")
						if (i === 'unpaid_order') {
							if (res[i] && JSON.stringify(res[i]) !== '{}') {
								this[i] = res[i]
							}
						} else {
							this[i] = res[i];

						}

					}
					if (this.unpaid_order) {
						console.log(this.showtime(this.unpaid_order.service_time))
						this.end_t = this.showtime(this.unpaid_order.service_time);
						let timer = null;
						if (this.end_t !== '已过期') {
							timer = setInterval(() => {
								if (this.end_t === '已过期') {
									clearInterval(timer);
									return;
								}
								this.end_t = this.showtime(this.unpaid_order.service_time)
							}, 1000)
						}
					}
				});
				// 获取客服信息 api/user/customerService
				/* 	this.$http.post('api/user/customerService').then(res =>{
						console.log(res,'xxxx')
						let { mobile } = res;
						this.mobiles = mobile;
					}) */

			},
			toPath(url) {
				console.log(url);
				if (url == '/bundle/pages/daili/daili' && this.is_personal == 1) {
					window.open('https://play.bozhoukeji.cn/ph5/#/')
					return
				}
				// if (url == '/bundle/pages/settled/settled' && this.is_technician == 1) {
				// 	window.open('https://play.bozhoukeji.cn/jh5/#/')
				// 	return
				// }
				//达人   https://play.bozhoukeji.cn/jh5/#/
				//个人   https://play.bozhoukeji.cn/ph5/#/   				
				uni.navigateTo({
					url
				})
			},
			toPath1() {
				uni.navigateTo({
					// url: '/bundle/pages/daili/daili1?status=' + 2
					url: '/bundle/pages/daili/daili1?status=' + this.is_partner
				})
			},
			toOrder(index) {
				uni.setStorageSync('tabsIndex', index);
				uni.reLaunch({
					url: '/pages/order/order'
				})
			},
			call() {
				uni.makePhoneCall({
					phoneNumber: this.phone1,
					success: function(e) {
						console.log(e);
					},
					fail: function(e) {
						console.log(e);

					}
				})
				// // #ifdef APP-PLUS
				// plus.runtime.openURL(this.reft) //这里默认使用外部浏览器打开而不是内部web-view组件打开
				// // #endif
				// // #ifdef H5
				// window.open(this.reft)
				// // #endif
			},

		}
	};
</script>

<style scoped lang="scss">
	page {
		background-color: #F6F8FA;
		padding-bottom: 120rpx;
		/* #ifdef MP||APP-PLUS */
		padding-top: $MPTop;
		/* #endif */

	}

	.topView {
		padding-top: 36rpx;

		/* #ifdef MP||APP-PLUS */
		padding-top: 36+40rpx;
		/* #endif */

		width: 100%;
		height: 378+40rpx;
		background: linear-gradient(90deg, #C74BF0 0%, #8438FC 100%);
		opacity: 1;
	}

	.avatarImage {
		margin-left: 30rpx;
		width: 116rpx;
		height: 116rpx;
		border-radius: 50%;
		background-color: #f4f4f4;
	}

	.nickname {
		margin-left: 16rpx;
		font-size: 36rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
	}

	.topView1 {
		padding: 0 34rpx;
		margin-top: 50rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
		height: 148rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
	}

	.money {
		font-size: 48rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.moneyTitle {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #808080;
	}

	.chong {
		width: 192rpx;
		height: 66rpx;
		background: #FBE4AE;
		border-radius: 24rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #563E12;
	}


	.bottom {
		width: 100%;
		height: 250rpx;
		padding: 20rpx;
		box-sizing: border-box;

		.bottom-box {
			width: 100%;
			min-height: 250rpx;
			background-color: #FFFFFF;
			border-radius: 30rpx;
			padding: 20rpx;

			.bottom-top {
				width: 100%;
				height: 50rpx;
				font-size: 30rpx;
				font-weight: 700;
			}

			.bottom-top2 {
				width: 100%;
				height: 50rpx;
				font-size: 30rpx;
				font-weight: 600;
				display: flex;
				justify-content: space-between;

				.Newtext {
					font-size: 24rpx;
					display: flex;
					align-items: center;
					color: #999;
					font-weight: 400;
				}
			}

			.bottom-b {
				width: 100%;
				height: 70%;
				margin-top: 20rpx;
				/* background-color: #FFB18B; */
				display: flex;
				flex-wrap: wrap;
				justify-content: flex-start;
				align-items: center;
				font-size: 26rpx;

				.bottom-b1 {
					width: 25%;
					height: 130rpx;
					margin-top: 2rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: space-around;

				}
			}
		}
	}

	.topView2 {
		margin: 20rpx 30rpx;
		margin-bottom: 0rpx;
	}

	.topView3 {
		padding: 0 20rpx;
		width: 334rpx;
		height: 160rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
	}

	.topView3Title {
		font-size: 32rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #000000;
	}

	.topView3Title1 {
		font-size: 26rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #6F6F6F;
	}

	.topView3Image {
		width: 80rpx;
		height: 80rpx;
	}
</style>